10 RANDOMIZE TIMER:KEY OFF:WIDTH 40:DEFINT A-Z:DIM A(4),P(4)
20 WHILE E=0:CLS:LOCATE 4,10,1:PRINT "*** Bulls and Cows ***";
30 T=0:A(0)=INT(RND*100) MOD 10:FOR I=1 TO 3:N=-1
40 WHILE N=-1:N=INT(RND*100) MOD 10
45 FOR J=0 TO I-1:IF N=A(J) THEN N=-1
50 NEXT J:WEND:A(I)=N:NEXT I
60 WHILE E=0:LOCATE 6,15:PRINT SPC(24);
70 LOCATE 6,15:PRINT "Guess: ":GOSUB 300
80 IF E=2 THEN GOTO 150
90 A=0:B=0:FOR I=0 TO 3:FOR J=0 TO 3
100 IF A(I)=P(J) THEN IF I=J THEN A=A+1 ELSE B=B+1
110 NEXT J:NEXT I
120 T=T+1:LOCATE 8+T,15:PRINT USING "#. ";T;
130 PRINT USING "#";P(0);P(1);P(2);P(3);:PRINT USING " #A#B";A;B
140 IF A=4 AND B=0 THEN E=1 ELSE IF T>=8 THEN E=2
150 WEND
160 IF E=2 THEN LOCATE 19,7:PRINT "You Lose! The answer is: ";:PRINT USING "#";A(0);A(1);A(2);A(3);:SOUND 100,2
170 IF E=1 THEN LOCATE 19,17:PRINT "You win!";:SOUND 500,1:SOUND 1000,1
180 IF E>0 THEN LOCATE 21,13:PRINT "Play again? (Y/N)";
190 WHILE E>0:K$=INPUT$(1)
200 IF K$="y" OR K$="Y" THEN E=0 ELSE IF K$="n" OR K$="N" THEN E=-1
210 WEND
220 WEND
230 CLS:WIDTH 80:END
300 L=0:WHILE 1
310 LOCATE 6,22+L:K=ASC(INPUT$(1))
320 IF K=27 THEN E=2:RETURN
330 IF K=13 AND L=4 THEN RETURN
340 IF K=8 AND L>0 THEN L=L-1:LOCATE 6,22+L:PRINT " ";:LOCATE 6,22+L
350 IF K>=48 AND K<=57 AND L<4 THEN GOSUB 400
360 WEND
400 N=K-48:FOR I=0 TO L-1
410 IF P(I)=N THEN RETURN
420 NEXT I
430 PRINT CHR$(K);:P(L)=N:L=L+1
440 RETURN

